package com.itheima.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.DTO.EmpDTO;
import com.itheima.pojo.Emp;
import com.itheima.pojo.GenderOption;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper extends BaseMapper<Emp> {
    /**
     * 根据查询条件查询员工
     */
    @Select("select e.*, d.name AS deptName from emp e left join dept d on e.dept_id = d.id ${ew.customSqlSegment}")
    Page<Emp> list2(@Param("page") IPage<Emp> page, @Param("ew") QueryWrapper<Emp> wrapper);

    /**
     * 新增员工数据
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void mySave(Emp emp);


    //    该接口用于根据主键ID查询员工的信息
    Emp getInfo(Integer id);

    //<!--根据ID更新员工信息-->
    void myUpdateById(Emp emp);

    //    接口描述：统计各个职位的员工人数
    List<Map<String, Object>> countEmpJobData();

    //统计员工性别信息
    List<GenderOption> countEmpGenderData();

    //：该接口用于查询全部员工信息
    @Select("select e.* from emp e left join clazz c on e.id = c.master_id")
    List<EmpDTO> list();

}